<template>
  <el-container class="home-container">
    <el-aside class="aside-container" :width="menuCollapse ? '64px' : '200px'">
      <div class="logo-area">
        <img
          src="../assets/wzut-logo.jpg"
          :width="menuCollapse ? '30px' : '80px'"
        />
        <div v-show="!menuCollapse">框架设计课程</div>
      </div>
      <hr />
      <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        background-color="#253a49"
        text-color="#fff"
        active-text-color="#ffd04b"
        :collapse="menuCollapse"
        :collapse-transition="false"
        :router="true"
      >
        <el-submenu v-for="item in menuList" :index="item.id" :key="item.id">
          <template slot="title">
            <i :class="item.iconClass"></i>
            <span>{{item.title}}</span>
          </template>
        <el-menu-item v-for="subItem in item.children" :index="subItem.route" :key="subItem.id">
          <i :class="subItem.iconClass"></i>
          <span slot="title">{{subItem.title}}</span>
        </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header class="header-container">
        <div class="toggle-button">
          <i
            :class="menuCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
            @click="toggleMenuCollapse"
          ></i>
        </div>

        <el-dropdown>
          <span class="el-dropdown-link">
            用户名<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item divided>退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-main class="work-container">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item v-for="item in breadCumb" :to="item.path" :key="item.path">
            {{ item.meta }}
          </el-breadcrumb-item>
        </el-breadcrumb>

        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menuCollapse: false,
      breadCumb: [],
      menuList: [
          {id:'1', title:'系统管理', iconClass:'el-icon-setting', children:[
              {id:'1-1', title:'用户管理', iconClass:'el-icon-user', route:'/user'},
              {id:'1-2', title:'角色管理', iconClass:'el-icon-house', route:'/role'},
              {id:'1-3', title:'组织管理', iconClass:'el-icon-mobile', route:'/dept'},
              {id:'1-4', title:'菜单管理', iconClass:'el-icon-dish', route:'/menu'},
          ]}
      ]
    };
  }, //end of data
  methods: {
    toggleMenuCollapse() {
      this.menuCollapse = !this.menuCollapse;
    },
  },
  created(){
      this.breadCumb = this.$route.matched
  },
  watch:{
      $route: {
          handler(){
              this.breadCumb = this.$route.matched
          }
      }
  }
};
</script>

<style lang="less" scoped>
.home-container {
  background-color: blue;
  height: 100%;
}

.aside-container {
  background-color: #253a49;
  .el-menu {
    border-right: 0px;
  }
  .logo-area {
    height: 120px;
    padding: 20px;
    width: 100%;
    position: relative;
    left: 50%;
    transform: translate(-50%, 0%);
    text-align: center;
    color: lightgray;
  }
  hr {
    border: 1px inset grey;
  }
}

.header-container {
  background-color: #fcfcfc;
  border-bottom: #eeeeee 1px solid;
  font-size: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .toggle-button {
    align-items: center;
    cursor: pointer;
  }
}

.work-container {
  background-color: #fff;
}
</style>